<?php
session_start(); 
if(!isset($_SESSION['userName'])){
header( 'location: ../index.php' ); 
}

include("../conf/connect.php");
	$user_id = $_SESSION['user_id'];
	$qus_no = $_GET['qus'];
	$hid = $_SESSION['usrHHid'];
	$resId =$_SESSION['lid'];
	$respondent=$_SESSION['hello'];
	

  if($qus_no =='hid'){
  		$house_id=$_POST['HHHid'];
    	$_SESSION['usrHHid']=$house_id ;
		$adult_check="SELECT * FROM adult_question where hid=$house_id and user_id=$user_id";
		$adult_result = mysql_query($adult_check) or die ("problem hid");
		$flag=0;
		while($row = mysql_fetch_assoc($adult_result)){
			$adult_resp_id=$row['resp_id'];
			if($adult_resp_id==''){
				$flag++;
			}
		}
		
		if($flag=='0'){
			$sql="INSERT INTO education (id, hid, user_id, is_delete, status) 
					VALUES 
				('', '$house_id','$user_id',  0, 0)";
			mysql_query($sql) or die ("problem budget_heads");
			$sql="INSERT INTO adult_question (id, hid, user_id, is_delete, status) 
					VALUES 
				('', '$house_id','$user_id',  0, 0)";
			mysql_query($sql) or die ("problem budget_heads");
			$sql="INSERT INTO chronic (id, hid, user_id,  is_delete, status) 
					VALUES 
				('', '$house_id','$user_id', 0, 0)";
			mysql_query($sql) or die ("problem budget_heads");
			$sql="INSERT INTO acute (id, hid, user_id,  is_delete, status) 
					VALUES 
				('', '$house_id','$user_id', 0, 0)";
			mysql_query($sql) or die ("problem budget_heads");
			$sql="INSERT INTO med1 (id, hid, user_id, is_delete, status) 
					VALUES 
				('', '$house_id','$user_id',  0, 0)";
			mysql_query($sql) or die ("problem budget_heads");
			$sql="INSERT INTO marital1 (id, hid, user_id, is_delete, status) 
					VALUES 
				('', '$house_id','$user_id',  0, 0)";
			mysql_query($sql) or die ("problem budget_heads");
			header( "location: question.php?serial=member" );
		}
		else{
			header( "location: question.php?serial=member" );
		}
  } 
  if($qus_no =='member'){
    	$resp_id=$_POST['memid'];
		$_SESSION['hello']=$resp_id;
		
		$adult_check="SELECT * FROM adult_question where hid=$hid and user_id=$user_id";
		$adult_result = mysql_query($adult_check) or die ("problem budget_heads");
		$flag=0;
		while($row = mysql_fetch_assoc($adult_result)){
			$adult_resp_id=$row['resp_id'];
			if($adult_resp_id==$resp_id){
				$flag++;
			}
		}
				
		$adult_check="SELECT * FROM adult_question where hid=$hid and user_id=$user_id and resp_id IS NULL";
		$adult_result = mysql_query($adult_check) or die ("problem budget_heads");
		$adult_row = mysql_fetch_assoc($adult_result);
		$adult_id=$adult_row['id'];
		
		$chronic_check="SELECT * FROM chronic where hid=$hid and user_id=$user_id and resp_id IS NULL";
		$chronic_result = mysql_query($chronic_check) or die ("problem budget_heads");
		$chronic_row = mysql_fetch_assoc($chronic_result);
		$chronic_id=$chronic_row['id'];
		
		$acute_check="SELECT * FROM acute where hid=$hid and user_id=$user_id and resp_id IS NULL";
		$acute_result = mysql_query($acute_check) or die ("problem budget_heads");
		$acute_row = mysql_fetch_assoc($acute_result);
		$acute_id=$acute_row['id'];
		
		$edu_check="SELECT * FROM education where hid=$hid and user_id=$user_id and resp_id IS NULL";
		$edu_result = mysql_query($edu_check) or die ("problem budget_heads");
		$edu_row = mysql_fetch_assoc($edu_result);
		$edu_id=$edu_row['id'];
		
		$med_check="SELECT * FROM med1 where hid=$hid and user_id=$user_id and resp_id IS NULL";
		$med_result = mysql_query($med_check) or die ("problem budget_heads");
		$med_row = mysql_fetch_assoc($med_result);
		$med_id=$med_row['id'];
		
		$mar_check="SELECT * FROM marital1 where hid=$hid and user_id=$user_id and resp_id IS NULL";
		$mar_result = mysql_query($mar_check) or die ("problem budget_heads");
		$mar_row = mysql_fetch_assoc($mar_result);
		$mar_id=$mar_row['id'];
		
		if($flag=='0'){	
			$sql="UPDATE education set resp_id='$resp_id'  WHERE  hid ='$hid' and id='$edu_id'";
			mysql_query($sql) or die ("problem 2ND BLOCK OF members");
			$sql="UPDATE adult_question set resp_id='$resp_id'  WHERE  hid ='$hid' and id='$adult_id'";
			mysql_query($sql) or die ("problem 2ND BLOCK OF members");		
			$sql="UPDATE chronic set resp_id='$resp_id'  WHERE hid ='$hid' and id='$chronic_id'";
			mysql_query($sql) or die ("problem 2ND BLOCK OF members");
			$sql="UPDATE acute set resp_id='$resp_id'  WHERE hid ='$hid' and id='$acute_id'";
			mysql_query($sql) or die ("problem 2ND BLOCK OF members");
			$sql="UPDATE med1 set resp_id='$resp_id'  WHERE hid ='$hid' and id='$med_id'";
			mysql_query($sql) or die ("problem 2ND BLOCK OF members");
			$sql="UPDATE marital1 set resp_id='$resp_id'  WHERE hid ='$hid' and id='$mar_id'";
			mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		}
		header( "location: question.php?serial=ed01" );
  } 
  else if($qus_no =='ed01'){
  		$ed01 = $_POST["ed01"];
		$ed02_1 = $_POST["ed02_1"];
		$ed02_2 = $_POST["ed02_2"];
		$ed02_3 = $_POST["ed02_3"];
		$ed03 = $_POST["ed03"];
		$sql="UPDATE education set ed01='$ed01', ed02_1='$ed02_1', ed02_2='$ed02_2', ed02_3='$ed02_3', ed03='$ed03'  WHERE  hid ='$hid' and resp_id=$respondent";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		if($ed01=='0'||$ed02_1=='0'||$ed02_2=='0'||$ed02_3=='0'||$ed03=='0'){
			header( "location: question.php?serial=ed01" );
		}
		else if($ed03=='3'){
			header( "location: question.php?serial=ed02" );
		}
		else{
			header( "location: question.php?serial=ed03" );
		}	
  } 
  else if($qus_no =='ed02'){
  		$ed04 = $_POST["ed04"];
		$sql="UPDATE education set ed04='$ed04'  WHERE  hid ='$hid' and resp_id=$respondent";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		if($ed04=='0'){
			header( "location: question.php?serial=ed02" );
		}
		else{
			header( "location: question.php?serial=emp01" );
		}	
  } 
  else if($qus_no =='ed03'){
  		$ed05 = $_POST["d1"].$_POST["d2"];
		$ed06 = $_POST["ed06"];
		$sql="UPDATE education set ed05='$ed05', ed06='$ed06' WHERE  hid ='$hid' and resp_id=$respondent";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		if($ed05=='00'||$ed06=='0'){
			header( "location: question.php?serial=ed03" );
		}
		else{
			header( "location: question.php?serial=ed04" );
		}	
  } 
  else if($qus_no =='ed04'){
  		$ed07 = $_POST["d1"].$_POST["d2"];
		$ed08 = $_POST["ed08"];
		$sql="UPDATE education set ed07='$ed07', ed08='$ed08' WHERE  hid ='$hid' and resp_id=$respondent";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		if($ed08=='0'){
			header( "location: question.php?serial=ed04" );
		}
		if($ed08=='1'){
			header( "location: question.php?serial=emp01" );
		}
		else{
			header( "location: question.php?serial=ed05" );
		}	
  } 
  else if($qus_no =='ed05'){
  		$ed09 = $_POST["d1"].$_POST["d2"];
		$ed10 = $_POST["ed10"];
		$sql="UPDATE education set ed09='$ed09', ed10='$ed10' WHERE  hid ='$hid' and resp_id=$respondent";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		if($ed10=='00'||$ed10=='0'){
			header( "location: question.php?serial=ed05" );
		}
		else{
			header( "location: question.php?serial=emp01" );
		}	
  } 
  else if($qus_no =='emp01'){
  		$emp01 = $_POST["emp01"];
		$sql="UPDATE adult_question set emp01='$emp01'  WHERE  hid ='$hid' and resp_id=$respondent";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		if($emp01=='0'){
			header( "location: question.php?serial=emp01" );
		}
		else{
			header( "location: question.php?serial=emp" );
		}	
  } 
  else if($qus_no =='emp'){
  		$emp02 = $_POST["emp02"];
		$emp03 = $_POST["emp03"];
		$emp04_a = $_POST["emp04_a"];
		$emp04_b = $_POST["emp04_b"];
		$emp05 = $_POST["emp05"];
		$emp06 = $_POST["emp06"];
		$emp07 = $_POST["income"];
		$sql="UPDATE adult_question set emp02='$emp02', emp03='$emp03', emp04_a='$emp04_a', emp04_b='$emp04_b', emp05='$emp05',emp06='$emp06',emp07='$emp07' WHERE  hid ='$hid' and resp_id='$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		$mql="SELECT * FROM adult_question WHERE hid ='$hid' and resp_id=$respondent";
				$result = mysql_query($mql) or die ("problem budget_heads");
				$row = mysql_fetch_assoc($result);
		if($row['emp01']=='1'){			
			if($emp04_a=='00'||$emp04_b=='00'||$emp05=='00'||$emp06=='00'||$emp07==''){
				//echo "hello";	
				header( "location: question.php?serial=emp" );
				exit;
			}			
		}
		elseif($row['emp01']=='2'){
			if($emp02=='00'||$emp03=='00'||$emp06=='00'||$emp07==''){
				header( "location: question.php?serial=emp" );
				exit;
			}
		}
				
		//header( "location: question.php?serial=spn01" );
		header( "location: question.php?serial=mh01" );
		
  } 
  else if($qus_no =='mh01'){
  		$mh01 = $_POST["mh01"];
		$sql="UPDATE marital1 set mh01='$mh01' WHERE  hid ='$hid' and resp_id=$respondent";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		if($mh01=='0'){
			header( "location: question.php?serial=mh01" );
		}
		elseif($mh01=='1'){
			header( "location: question.php?serial=spn01" );
		}
		else{
			header( "location: question.php?serial=mh02" );
		}	
  } 
  else if($qus_no =='mh02'){
  		$mh02 = $_POST["d1"].$_POST["d2"];
		$mh03 = $_POST["mh03"];
		$sql="UPDATE marital1 set mh02='$mh02', mh03='$mh03' WHERE  hid ='$hid' and resp_id=$respondent";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		if($mh02=='00'||$mh03=='0'){
			header( "location: question.php?serial=mh02" );
		}
		else{
			header( "location: question.php?serial=mh03" );
		}	
  } 
  else if($qus_no =='mh03'){
  		$no=$_POST['no'];
		$insert=$_POST['insert'];
		$id=$_POST['id'];
  		$mh04 = $_POST["mh04"];
  		$mh05a = $_POST["d1"].$_POST["d2"];
		$mh05b = $_POST["d3"].$_POST["d4"];
		$mh06 = $_POST["mh06"];
		if($insert==''){
			$sql="INSERT INTO marital2 (id, hid, user_id, resp_id, mh04, mh05a, mh05b, mh06, is_delete, status)
					VALUES
					('', '$hid', '$user_id', '$respondent', '$mh04', '$mh05a', '$mh05b', '$mh06', 0, 0)";
					mysql_query($sql) or die ("problem 2ND BLOCK OF members");
			
			if($mh04==''||$mh05a=='00'||$mh05b=='00'||$mh06=='0'){
				$sql="SELECT * FROM marital2 WHERE hid=$hid and user_id=$user_id and resp_id=$respondent ORDER BY id DESC LIMIT 1";
				$result=mysql_query($sql);
				$row=mysql_fetch_assoc($result);
				$id=$row['id'];
				header( "location: question.php?serial=mh03&no=$no&id=$id&insert=u" );
			}
			elseif($mh06=='1'){
				$sql="SELECT * FROM marital2 WHERE hid=$hid and user_id=$user_id and resp_id=$respondent ORDER BY id DESC LIMIT 1";
				$result=mysql_query($sql);
				$row=mysql_fetch_assoc($result);
				$id=$row['id'];
				header( "location: question.php?serial=mh05&no=$no&id=$id" );
			}	
			else{
				$sql="SELECT * FROM marital2 WHERE hid=$hid and user_id=$user_id and resp_id=$respondent ORDER BY id DESC LIMIT 1";
				$result=mysql_query($sql);
				$row=mysql_fetch_assoc($result);
				$id=$row['id'];
				header( "location: question.php?serial=mh04&no=$no&id=$id" );
			}
		}
		elseif($insert=='u'){
			$sql="UPDATE marital2 SET mh04='$mh04',mh05a='$mh05a', mh05b='$mh05b', mh06='$mh06' WHERE id='$id'";
					mysql_query($sql) or die ("problem update");
			
			if($mh05a=='00'||$mh05b=='00'||$mh06=='0'){
				$sql="SELECT * FROM marital2 WHERE hid=$hid and user_id=$user_id and resp_id=$respondent ORDER BY id DESC LIMIT 1";
				$result=mysql_query($sql);
				$row=mysql_fetch_assoc($result);
				$id=$row['id'];
				header( "location: question.php?serial=mh03&no=$no&id=$id&insert=u" );
			}
			elseif($mh06=='1'){
				$sql="SELECT * FROM marital2 WHERE hid=$hid and user_id=$user_id and resp_id=$respondent ORDER BY id DESC LIMIT 1";
				$result=mysql_query($sql);
				$row=mysql_fetch_assoc($result);
				$id=$row['id'];
				header( "location: question.php?serial=mh05&no=$no&id=$id" );
			}	
			else{
				$sql="SELECT * FROM marital2 WHERE hid=$hid and user_id=$user_id and resp_id=$respondent ORDER BY id DESC LIMIT 1";
				$result=mysql_query($sql);
				$row=mysql_fetch_assoc($result);
				$id=$row['id'];
				header( "location: question.php?serial=mh04&no=$no&id=$id" );
			}
		}
  } 
  else if($qus_no =='mh04'){
  		$id=$_POST['id'];
		$no=$_POST['no'];
  		$mh07 = $_POST["mh07"];
		$sql="UPDATE marital2 set mh07='$mh07' WHERE  id=$id";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
				
		if($mh07==''){
			header( "location: question.php?serial=mh04&no=$no&id=$id" );
		}
		else{
			header( "location: question.php?serial=mh05&no=$no&id=$id" );
		}	
  }
  else if($qus_no =='mh05'){
  		$id=$_POST['id'];
		$no=$_POST['no'];
  		$mh08 = $_POST["mh08"];
		$sql="UPDATE marital2 set mh08='$mh08' WHERE  id=$id";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
				
		if($mh08=='0'){
			header( "location: question.php?serial=mh05&no=$no&id=$id" );
		}
		else if($mh08=='1'){
			header( "location: question.php?serial=mh08&no=$no&id=$id" );
		}
		else if($mh08=='3'){
			header( "location: question.php?serial=mh07&no=$no&id=$id" );
		}
		else{
			header( "location: question.php?serial=mh06&no=$no&id=$id" );
		}	
  } 
  else if($qus_no =='mh06'){
  		$id=$_POST['id'];
		$no=$_POST['no'];
  		$mh09 = $_POST["mh09"];
		$sql="UPDATE marital2 set mh09='$mh09' WHERE  id=$id";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
				
		if($mh09=='0'){
			header( "location: question.php?serial=mh06&no=$no&id=$id" );
		}
		else{
			header( "location: question.php?serial=mh07&no=$no&id=$id" );
		}	
  } 
  else if($qus_no =='mh07'){
  		$id=$_POST['id'];
		$no=$_POST['no'];
  		$mh10 = $_POST["d1"].$_POST["d2"];
		$sql="UPDATE marital2 set mh10='$mh10' WHERE  id=$id";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
				
		if($mh10=='00'){
			header( "location: question.php?serial=mh07&no=$no&id=$id" );
		}
		else{
			header( "location: question.php?serial=mh08&no=$no&id=$id" );
		}	
  }
  else if($qus_no =='mh08'){
  		$id=$_POST['id'];
		$no=$_POST['no'];
  		$mh11 = $_POST["d1"].$_POST["d2"];
		$sql="UPDATE marital2 set mh11='$mh11' WHERE  id=$id";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		$sql="SELECT  mh02 FROM marital1 WHERE hid = '$hid' and resp_id = '$respondent' ";
		$result=mysql_query($sql);
		$row = mysql_fetch_assoc($result);
		$end=$row['mh02'];
		$no=$no+1;
	
		if($no<=$end){
			header( "location: question.php?serial=mh03&no=$no" );
		}
		else{
			header( "location: question.php?serial=spn01" );
		}
	}
  else if($qus_no =='spn_01'){
  		$spn01_a = $_POST["spn01_a"];
		$spn01_b = $_POST["spn01_b"];
		$spn01_c = $_POST["spn01_c"];
		$spn01_d = $_POST["spn01_d"];
		$spn01_e = $_POST["spn01_e"];
		
		
  		$sql="UPDATE adult_question set spn01_a='$spn01_a', spn01_b='$spn01_b', spn01_c='$spn01_c', spn01_d='$spn01_d', spn01_e='$spn01_e' WHERE user_id='$user_id' and hid = '$hid' and resp_id = '$respondent'";
	mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		mysql_query($sql) or die ("problem budget_heads");
	if($spn01_a=='0'||$spn01_b=='0'||$spn01_c=='0'||$spn01_d=='0'||$spn01_e=='0'){
		header( "location: question.php?serial=spn01" );
	}
	elseif($spn01_a=='1'){
	    header( "location: question.php?serial=spn02a" );
	}
	elseif($spn01_b=='1'){
	    header( "location: question.php?serial=spn02b" );
	}
	elseif($spn01_c=='1'){
	    header( "location: question.php?serial=spn02c" );
	}
	elseif($spn01_d=='1'){
	    header( "location: question.php?serial=spn02d" );
	}
	elseif($spn01_e=='1'){
	    header( "location: question.php?serial=spn02e" );
	}
	else header("location: question.php?serial=gh01");	
		
  } 
  else if($qus_no =='spn02a'){
  		$spn02_a = $_POST["spn02_a"];
		$sql="UPDATE adult_question set spn02_a='$spn02_a' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn02_a=='0'){
			header( "location: question.php?serial=spn02a" );
		}
		elseif($spn02_a=='1'){
			header( "location: question.php?serial=spn02y" );
		}
		elseif($spn02_a=='3'){
			header( "location: question.php?serial=spn02n" );
		}	
  }
  else if($qus_no =='spn02b'){
  		$spn02_b = $_POST["spn02_b"];
		$sql="UPDATE adult_question set spn02_b='$spn02_b' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn02_b=='0'){
			header( "location: question.php?serial=spn02b" );
		}
		elseif($spn02_b=='1'){
			header( "location: question.php?serial=spn02by" );
		}
		elseif($spn02_b=='3'){
			header( "location: question.php?serial=spn02bn" );
		}	
  }
  else if($qus_no =='spn02c'){
  		$spn02_c = $_POST["spn02_c"];
		$sql="UPDATE adult_question set spn02_c='$spn02_c' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn02_c=='0'){
			header( "location: question.php?serial=spn02c" );
		}
		elseif($spn02_c=='1'){
			header( "location: question.php?serial=spn02cy" );
		}
		elseif($spn02_c=='3'){
			header( "location: question.php?serial=spn02cn" );
		}	
  }
  else if($qus_no =='spn02d'){
  		$spn02_d = $_POST["spn02_d"];
		$sql="UPDATE adult_question set spn02_d='$spn02_d' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn02_d=='0'){
			header( "location: question.php?serial=spn02d" );
		}
		elseif($spn02_d=='1'){
			header( "location: question.php?serial=spn02dy" );
		}
		elseif($spn02_d=='3'){
			header( "location: question.php?serial=spn02dn" );
		}	
  }
  else if($qus_no =='spn02e'){
  		$spn02_e = $_POST["spn02_e"];
		$sql="UPDATE adult_question set spn02_e='$spn02_e' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn02_e=='0'){
			header( "location: question.php?serial=spn02e" );
		}
		elseif($spn02_e=='1'){
			header( "location: question.php?serial=spn02ey" );
		}
		elseif($spn02_e=='3'){
			header( "location: question.php?serial=spn02en" );
		}	
  }
  
  else if($qus_no =='spn02y'){
  		$spn04_a = $_POST["t1"].$_POST["t2"];
		$spn05_a = $_POST["t3"].$_POST["t4"];
		$spn06_a = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn04_a='$spn04_a',spn05_a='$spn05_a',spn06_a='$spn06_a' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn04_a=='00'||$spn05_a=='00'||$spn06_a=='00'){
			header( "location: question.php?serial=spn02y" );
		}
		else{
			$sql=" SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_assoc($result);
				if($row['spn01_b']==1) header("location: question.php?serial=spn02b");
				elseif($row['spn01_c']==1) header("location: question.php?serial=spn02c");
				elseif($row['spn01_d']==1) header("location: question.php?serial=spn02d");
				elseif($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}	
  }
  else if($qus_no =='spn02n'){
  		$spn03_a = $_POST["t7"].$_POST["t8"];
  		$spn04_a = $_POST["t1"].$_POST["t2"];
		$spn05_a = $_POST["t3"].$_POST["t4"];
		$spn06_a = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn03_a='$spn03_a', spn04_a='$spn04_a',spn05_a='$spn05_a',spn06_a='$spn06_a' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn03_a=='00'||$spn04_a=='00'||$spn05_a=='00'||$spn06_a=='00'){
			header( "location: question.php?serial=spn02n" );
		}
		else{
			$sql="SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_array($result);
				if($row['spn01_b']==1) header("location: question.php?serial=spn02b");
				elseif($row['spn01_c']==1) header("location: question.php?serial=spn02c");
				elseif($row['spn01_d']==1) header("location: question.php?serial=spn02d");
				elseif($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}		
  }
  else if($qus_no =='spn02by'){
  		$spn04_b = $_POST["t1"].$_POST["t2"];
		$spn05_b = $_POST["t3"].$_POST["t4"];
		$spn06_b = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn04_b='$spn04_b',spn05_b='$spn05_b',spn06_b='$spn06_b' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn04_b=='00'||$spn05_b=='00'||$spn06_b=='00'){
			header( "location: question.php?serial=spn02by" );
		}
		else{
			$sql=" SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_assoc($result);
				if($row['spn01_c']==1) header("location: question.php?serial=spn02c");
				elseif($row['spn01_d']==1) header("location: question.php?serial=spn02d");
				elseif($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}	
  }
  else if($qus_no =='spn02bn'){
  		$spn03_b = $_POST["t7"].$_POST["t8"];
  		$spn04_b = $_POST["t1"].$_POST["t2"];
		$spn05_b = $_POST["t3"].$_POST["t4"];
		$spn06_b = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn03_b='$spn03_b', spn04_b='$spn04_b',spn05_b='$spn05_b',spn06_b='$spn06_b' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn03_b=='00'||$spn04_b=='00'||$spn05_b=='00'||$spn06_b=='00'){
			header( "location: question.php?serial=spn02bn" );
		}
		else{
			$sql="SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_array($result);
				if($row['spn01_c']==1) header("location: question.php?serial=spn02c");
				elseif($row['spn01_d']==1) header("location: question.php?serial=spn02d");
				elseif($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}		
  }
  else if($qus_no =='spn02cy'){
  		$spn04_c = $_POST["t1"].$_POST["t2"];
		$spn05_c = $_POST["t3"].$_POST["t4"];
		$spn06_c = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn04_c='$spn04_c',spn05_c='$spn05_c',spn06_c='$spn06_c' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn04_c=='00'||$spn05_c=='00'||$spn06_c=='00'){
			header( "location: question.php?serial=spn02cy" );
		}
		else{
			$sql=" SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_assoc($result);
				if($row['spn01_d']==1) header("location: question.php?serial=spn02d");
				elseif($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}	
  }
  else if($qus_no =='spn02cn'){
  		$spn03_c = $_POST["t7"].$_POST["t8"];
  		$spn04_c = $_POST["t1"].$_POST["t2"];
		$spn05_c = $_POST["t3"].$_POST["t4"];
		$spn06_c = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn03_c='$spn03_c', spn04_c='$spn04_c',spn05_c='$spn05_c',spn06_c='$spn06_c' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn03_c=='00'||$spn04_c=='00'||$spn05_c=='00'||$spn06_c=='00'){
			header( "location: question.php?serial=spn02cn" );
		}
		else{
			$sql="SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_array($result);
				if($row['spn01_d']==1) header("location: question.php?serial=spn02d");
				elseif($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}		
  }
  else if($qus_no =='spn02dy'){
  		$spn04_d = $_POST["t1"].$_POST["t2"];
		$spn05_d = $_POST["t3"].$_POST["t4"];
		$spn06_d = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn04_d='$spn04_d',spn05_d='$spn05_d',spn06_d='$spn06_d' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn04_d=='00'||$spn05_d=='00'||$spn06_d=='00'){
			header( "location: question.php?serial=spn02dy" );
		}
		else{
			$sql=" SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_assoc($result);
				if($row['spn01_e']==1) header("location: question.php?serial=spn02e");	
				else header("location: question.php?serial=gh01");		
		}	
  }
  else if($qus_no =='spn02dn'){
  		$spn03_d = $_POST["t7"].$_POST["t8"];
  		$spn04_d = $_POST["t1"].$_POST["t2"];
		$spn05_d = $_POST["t3"].$_POST["t4"];
		$spn06_d = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn03_d='$spn03_d', spn04_d='$spn04_d',spn05_d='$spn05_d',spn06_d='$spn06_d' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn03_d=='00'||$spn04_d=='00'||$spn05_d=='00'||$spn06_d=='00'){
			header( "location: question.php?serial=spn02dn" );
		}
		else{
			$sql="SELECT * FROM adult_question where hid = '$hid' and resp_id = '$respondent'";
			$result=mysql_query($sql);
			$row=mysql_fetch_array($result);
				if($row['spn01_e']==1) header("location: question.php?serial=spn02e");
				else header("location: question.php?serial=gh01");
			
		}		
  }
  else if($qus_no =='spn02ey'){
  		$spn04_e = $_POST["t1"].$_POST["t2"];
		$spn05_e = $_POST["t3"].$_POST["t4"];
		$spn06_e = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn04_e='$spn04_e',spn05_e='$spn05_e',spn06_e='$spn06_e' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn04_e=='00'||$spn05_e=='00'||$spn06_e=='00'){
			header( "location: question.php?serial=spn02ey" );
		}
		else{
			header("location: question.php?serial=gh01");			
		}	
  }
  else if($qus_no =='spn02en'){
  		$spn03_e = $_POST["t7"].$_POST["t8"];
  		$spn04_e = $_POST["t1"].$_POST["t2"];
		$spn05_e = $_POST["t3"].$_POST["t4"];
		$spn06_e = $_POST["t5"].$_POST["t6"];
		$sql="UPDATE adult_question set spn03_e='$spn03_e', spn04_d='$spn04_e',spn05_e='$spn05_e',spn06_e='$spn06_e' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($spn03_e=='00'||$spn04_e=='00'||$spn05_e=='00'||$spn06_e=='00'){
			header( "location: question.php?serial=spn02en" );
		}
		else{
			header("location: question.php?serial=gh01");
			
		}		
  }
  else if($qus_no =='gh01'){
  		$gh01 = $_POST["gh01"];
		$sql="UPDATE adult_question set gh01='$gh01' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($gh01=='0'){
			header( "location: question.php?serial=gh01" );
		}
		elseif($gh01=='1'){
			header( "location: question.php?serial=gh" );
		}
		elseif($gh01=='2'){
			header( "location: question.php?serial=gh02" );
		}	
		elseif($gh01=='3'){
			header( "location: question.php?serial=gh03" );
		}
		
  } 
  else if($qus_no =='gh02'){
  		$gh02 = $_POST["gh02"];
		$sql="UPDATE adult_question set gh02='$gh02' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($gh02=='0'){
			header( "location: question.php?serial=gh02" );
		}
		elseif($gh02=='1'){
			header( "location: question.php?serial=gh" );
		}	
		else{
			header( "location: question.php?serial=gh03" );
		}
		
  } 
  else if($qus_no =='gh03'){
  		$gh03 = $_POST["t1"].$_POST["t2"];
		$sql="UPDATE adult_question set gh03='$gh03' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($gh03=='00'){
			header( "location: question.php?serial=gh03" );
		}
		else{
			header( "location: question.php?serial=gh" );
		}				
  }
  else if($qus_no =='gh'){
  		$gh04 = $_POST["gh04"];
		$gh05 = $_POST["gh05"];
		$gh06 = $_POST["gh06"];
		$gh07 = $_POST["gh07"];
		$sql="UPDATE adult_question set gh04='$gh04', gh05='$gh05', gh06='$gh06', gh07='$gh07'  WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		if($gh04=='0'||$gh05=='0'||$gh06=='0'||$gh07=='0'){
			header( "location: question.php?serial=gh" );
		}
		else{
			header( "location: question.php?serial=gh08_a" );
		}				
  } 
  else if($qus_no =='gh08_a'){
  		$gh08_a_1 = $_POST["gh08_a_1"];
		$gh08_a_2 = $_POST["gh08_a_2"];
		$gh08_a_3 = $_POST["gh08_a_3"];
		$gh08_a_4 = $_POST["gh08_a_4"];
		$gh08_a_5 = $_POST["gh08_a_5"];
		$gh08_a_6 = $_POST["gh08_a_6"];
		$gh08_a_7 = $_POST["gh08_a_7"];
		$gh08_a_8 = $_POST["gh08_a_8"];
		$gh08_a_9 = $_POST["gh08_a_9"];
		$sql="UPDATE adult_question set gh08_a_1='$gh08_a_1', gh08_a_2='$gh08_a_2', gh08_a_3='$gh08_a_3',  gh08_a_4='$gh08_a_4',  gh08_a_5='$gh08_a_5', gh08_a_6='$gh08_a_6', gh08_a_7='$gh08_a_7', gh08_a_8='$gh08_a_8', gh08_a_9='$gh08_a_9'  WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
			header( "location: question.php?serial=cm01a1" );		
  } 
  else if($qus_no =='cm01a1'){
  		//echo "<pre>";
		
		$cm01a1 = $_POST['cm01a1'];
		
		$sql="UPDATE chronic set cm01a1_1='$cm01a1[1]', cm01a1_2='$cm01a1[2]', cm01a1_3='$cm01a1[3]', cm01a1_4='$cm01a1[4]', cm01a1_5='$cm01a1[5]', cm01a1_6='$cm01a1[6]', cm01a1_7='$cm01a1[7]', cm01a1_8='$cm01a1[8]', cm01a1_9='$cm01a1[9]', cm01a1_10='$cm01a1[10]', cm01a1_11='$cm01a1[11]', cm01a1_12='$cm01a1[12]', cm01a1_13='$cm01a1[13]', cm01a1_14='$cm01a1[14]', cm01a1_15='$cm01a1[15]', cm01a1_16='$cm01a1[16]', cm01a1_17='$cm01a1[17]', cm01a1_18='$cm01a1[18]', cm01a1_19='$cm01a1[19]', cm01a1_20='$cm01a1[20]', cm01a1_21='$cm01a1[21]', cm01a1_22='$cm01a1[22]'  WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		$back =0;
		for($j=1;$j<=22;$j++){
			//echo $cm01a1[$j];
			if($cm01a1[$j]==0){
				 $back=1;
				 break;
			}
		}
		//echo $back;
		if ($back ==1){
			header("location: question.php?serial=cm01a1" );
			exit;
		}
		
		$back =0;
		//echo "test";
		for($i=1;$i<=22;$i++){
			if($cm01a1[$i]=='1'){
				$back =$i;
				break;	 
				 
			}
		}
		if ($back !=0){
			header("location: question.php?serial=cm&no=$i" );
			exit;
			}
		else if ($back ==0){
			header( "location: question.php?serial=cm13" );
			exit;
			}		
  }
  else if($qus_no =='cm'){
  		 $no = $_POST['no'];
		 $start=$no+1;	
  		 $cm01a2= $_POST["cm01a2_$no"];
		 $cm02a= $_POST["cm02a_$no"];
		 $cm03a= $_POST["cm03a_$no"];
		 $cm04a= $_POST["cm04a_$no"];
		 $cm05a= $_POST["cm05a_$no"];
		 $cm06a= $_POST["cm06a_$no"];
		
		$sql="UPDATE chronic set cm01a2_$no='$cm01a2', cm02a_$no='$cm02a', cm03a_$no='$cm03a', cm04a_$no='$cm04a', cm05a_$no='$cm05a', cm06a_$no='$cm06a' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
				
		$sql="SELECT * FROM chronic WHERE hid = '$hid' and resp_id = '$respondent'";
				$result = mysql_query($sql) or die ("problem budget_heads");
				$row = mysql_fetch_assoc($result);	
				
		
		if($cm01a2=='0'||$cm02a=='0'||$cm03a=='0'||$cm04a=='0'||$cm05a=='0'||$cm06a=='0'){
			header("location: question.php?serial=cm&no=$no" );
		}
		else{	
			for($i=$start;$i<=22;$i++){
				$z=$row["cm01a1_$i"];
				if($z==1) {
					header("location: question.php?serial=cm&no=$i" );
					exit;
					}
			}	
		}	
		header( "location: question.php?serial=cm13" );		
  }
  else if($qus_no =='cm13'){
  		//echo "<pre>";
		
		$cm13 = $_POST['cm13'];
		//print_r($cm13);	
		$sql="UPDATE chronic set cm13_1='$cm13[1]', cm13_2='$cm13[2]', cm13_3='$cm13[3]', cm13_4='$cm13[4]', cm13_5='$cm13[5]', cm13_6='$cm13[6]', cm13_7='$cm13[7]', cm13_8='$cm13[8]', cm13_9='$cm13[9]', cm13_10='$cm13[10]', cm13_11='$cm13[11]', cm13_12='$cm13[12]', cm13_13='$cm13[13]', cm13_14='$cm13[14]', cm13_15='$cm13[15]', cm13_16='$cm13[16]', cm13_17='$cm13[17]' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		for($i=1;$i<=17;$i++){
			if($cm13[$i]==0){
				header("location: question.php?serial=cm13" );
				exit;
			}
		}
		header( "location: question.php?serial=cm14" );	
  }
  else if($qus_no =='cm14'){
			//echo "<pre>";
			
			$cm14 = $_POST['cm14'];
			//print_r($cm13);	
			$sql="UPDATE chronic set cm14='$cm14' WHERE  hid = '$hid' and resp_id = '$respondent'";
			mysql_query($sql) or die ("problem 2ND BLOCK OF members");
			
			if($cm14=='0'){
				header( "location: question.php?serial=cm14" );
			}
			else{
				header( "location: question.php?serial=cm14_y" );
			}	
  }
  else if($qus_no =='cm14_y'){
		//echo "<pre>";
		
		$cm14 = $_POST['cm14'];
		//print_r($cm14);	
		$sql="UPDATE chronic set cm14_1='$cm14[1]', cm14_2='$cm14[2]', cm14_3='$cm14[3]', cm14_4='$cm14[4]', cm14_5='$cm14[5]', cm14_6='$cm14[6]', cm14_7='$cm14[7]' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		for($i=1;$i<=7;$i++){
			if($cm14[$i]==0){
				header("location: question.php?serial=cm14_y" );
				exit;
			}
		}
		
		header( "location: question.php?serial=cm15" );	
  }
  else if($qus_no =='cm15'){
		//echo "<pre>";
		
		$cm15 = $_POST['cm15'];
		//print_r($cm13);	
		$sql="UPDATE chronic set cm15='$cm15' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		if($cm15=='0'){
			header( "location: question.php?serial=cm15" );
		}
		elseif($cm15=='1'){
			header( "location: question.php?serial=cm15_y" );
		}
		else{
			header( "location: question.php?serial=am01" );
		}	
  }
  
  else if($qus_no =='cm15_y'){
				
		$cm15 = $_POST['cm15'];
		//print_r($cm15);
		for($i=1;$i<=18;$i++){	
			$sql="UPDATE chronic set cm15_$i='$cm15[$i]' WHERE  hid = '$hid' and resp_id = '$respondent'";
			mysql_query($sql) or die ("problem 2ND BLOCK OF members");		
		}
				
		$back =0;
		for($j=1;$j<=18;$j++){
			//echo $cm01a1[$j];
			if($cm15[$j]==0){
				 $back=1;
				 break;
			}
		}
		//echo $back;
		if ($back ==1){
			header("location: question.php?serial=cm15_y" );
			exit;
		}
		
		$back =0;
		//echo "test";
		for($i=1;$i<=18;$i++){
			if($cm15[$i]=='1'){
				$back =$i;
				break;	 
				 
			}
		}
		if ($back !=0){
			header("location: question.php?serial=cm15a&no=$i" );
			exit;
			}
		else if ($back ==0){
			header( "location: question.php?serial=am01" );
			exit;
			}
  }
  else if($qus_no =='cm15a'){
  		 $no = $_POST['no'];
		 $start=$no+1;	
  		 $cm15a= $_POST["cm15a_$no"];
		 $cm15b= $_POST["cm15b_$no"];
		 $cm15c= $_POST["d1"].$_POST["d2"].$_POST["d3"];
		
		$sql="UPDATE chronic set cm15a_$no='$cm15a', cm15b_$no='$cm15b', cm15c_$no='$cm15c' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
				
		$sql="SELECT * FROM chronic WHERE hid = '$hid' and resp_id = '$respondent'";
				$result = mysql_query($sql) or die ("problem budget_heads");
				$row = mysql_fetch_assoc($result);	
				
		
		if($cm15a=='0'||$cm15b=='0'||$cm15c=='000'){
			header("location: question.php?serial=cm15a&no=$no" );
			break;
		}
		else{	
			for($i=$start;$i<=18;$i++){
				$z=$row["cm15_$i"];
				if($z==1) {
					header("location: question.php?serial=cm15a&no=$i" );
					exit;
					}
			}	
		}	
		header( "location: question.php?serial=am01" );		
  }
  else if($qus_no =='am01'){
		//echo "<pre>";		
		$am = $_POST['am'];
		//print_r($am);
		for($i=1;$i<=12;$i++){	
			$sql="UPDATE acute set am01_$i='$am[$i]' WHERE  hid = '$hid' and resp_id = '$respondent'";
			mysql_query($sql) or die ("problem 2ND BLOCK OF members");	
			//echo "<br>";	
		}
				
		$back =0;
		for($j=1;$j<=12;$j++){
			if($am[$j]==0){
				 $back=1;
				 break;
			}
		}
		if ($back ==1){
			header("location: question.php?serial=am01" );
			exit;
		}
		
		$back =0;
		for($i=1;$i<=12;$i++){
			if($am[$i]=='1'){
				$back =$i;
				break;	 
				 
			}
		}
		if ($back !=0){
			header("location: question.php?serial=am01a&no=$i" );
			exit;
			}
		else if ($back ==0){
			header( "location: medication.php?serial=med01" );
			exit;
			}
  }
  else if($qus_no =='am01a'){
  		 $no = $_POST['no'];
		 $start=$no+1;	
  		 $am03= $_POST["d1"].$_POST["d2"];
		 $am05= $_POST["d3"].$_POST["d4"];
		 $am06= $_POST["am06_$no"];
		
		$sql="UPDATE acute set am03_$no='$am03', am05_$no='$am05', am06_$no='$am06' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
				
		$sql="SELECT * FROM acute WHERE hid = '$hid' and resp_id = '$respondent'";
				$result = mysql_query($sql) or die ("problem budget_heads");
				$row = mysql_fetch_assoc($result);	
				
		
		if($am03=='00'||$am05=='00'||$am06=='0'){
			header("location: question.php?serial=am01a&no=$no" );
			break;
		}
		else{	
			for($i=$start;$i<=12;$i++){
				$z=$row["am01_$i"];
				if($z==1) {
					header("location: question.php?serial=am01a&no=$i" );
					exit;
					}
			}	
		}	
		header( "location: medication.php?serial=med01" );		
  }
   else if($qus_no =='med01'){
		//echo "<pre>";
		
		$med01 = $_POST['med01'];
		//print_r($cm13);	
		$sql="UPDATE med1 set med01='$med01' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		if($med01=='0'){
			header( "location: medication.php?serial=med01" );
		}
		elseif($med01=='1'){
			header( "location:  medication.php?serial=med02" );
		}
		else{
			$sql="UPDATE med1 set status='1' WHERE  hid = '$hid' and resp_id = '$respondent'";
			mysql_query($sql) or die ("problem 2ND BLOCK OF members");
			header( "location: ../index1.php" );
		}
  }
  else if($qus_no =='med02'){
				
		$med02 = $_POST['t1'];	
		$sql="UPDATE med1 set med02='$med02' WHERE  hid = '$hid' and resp_id = '$respondent'";
		mysql_query($sql) or die ("problem 2ND BLOCK OF members");
		
		if($med02=='00'){
			header( "location: medication.php?serial=med02" );
		}
		else{
			header( "location: medication.php?serial=med03" );
		}
  }
  else if($qus_no =='med03'){
		$no=$_POST['no'];
		$insert=$_POST['insert'];
		$id=$_POST['id'];		
		$med3=$_POST['med3'];
		$med4=$_POST['med4'];
		$med5=$_POST['med5'];
		$med6=$_POST['med6'];
		$med7=$_POST['d1'].$_POST['d2'];
		$med8=$_POST['med8'];
		$med9=$_POST['med9'];
		if($insert==''){
			$sql ="INSERT INTO med2 (id, hid, user_id, resp_id, med3, med4, med5, med6, med7, med8, med9, is_delete, status)
					VALUES
					('', '$hid', '$user_id', '$respondent', '$med3', '$med4', '$med5', '$med6', '$med7', '$med8', '$med9', 0, 0)";
					mysql_query($sql) or die ("problem 2ND BLOCK OF members");
			
			$sql="SELECT  med02 FROM med1 WHERE hid = '$hid' and resp_id = '$respondent' ";
			$result=mysql_query($sql);
			$row = mysql_fetch_assoc($result);
			$end=$row['med02'];
			$no=$no+1;
			if($med3==''||$med4==''||$med5=='0'||$med6==''||$med8=='0'||$med9==''){
				$sql="SELECT * FROM med2 WHERE hid=$hid and user_id=$user_id and resp_id=$respondent ORDER BY id DESC LIMIT 1";
				$result=mysql_query($sql);
				$row=mysql_fetch_assoc($result);
				$id=$row['id'];
				$serial=$no-1;
				header( "location: medication.php?serial=med03&no=$serial&id=$id&insert=u" );
			}
			else{
				if($no<=$end){
					header( "location: medication.php?serial=med03&no=$no" );
				}
				else{
					$sql="UPDATE med1 set status='1' WHERE  hid = '$hid' and resp_id = '$respondent'";
					mysql_query($sql) or die ("problem 2ND BLOCK OF members");
					header( "location: ../index1.php" );
				}
			}
		}
		elseif($insert=='u'){
					$sql ="UPDATE med2 SET med3='$med3', med4='$med4', med5='$med5', med6='$med6', med7='$med7', med8='$med8', med9='$med9' where id='$id'";
					mysql_query($sql) or die ("Problem inupdate");			
			
			$sql="SELECT  med02 FROM med1 WHERE hid = '$hid' and resp_id = '$respondent' ";
			$result=mysql_query($sql);
			$row = mysql_fetch_assoc($result);
			$end=$row['med02'];
			$no=$no+1;
			if($med3==''||$med4==''||$med5=='0'||$med6==''||$med8=='0'||$med9==''){
				$sql="SELECT * FROM med2 WHERE hid=$hid and user_id=$user_id and resp_id=$respondent ORDER BY id DESC LIMIT 1";
				$result=mysql_query($sql);
				$row=mysql_fetch_assoc($result);
				$id=$row['id'];
				$serial=$no-1;
				header( "location: medication.php?serial=med03&no=$serial&id=$id&insert=u" );
			}
			else{
				if($no<=$end){
					header( "location: medication.php?serial=med03&no=$no" );
				}
				else{
					$sql="UPDATE med1 set status='1' WHERE  hid = '$hid' and resp_id = '$respondent'";
					mysql_query($sql) or die ("problem 2ND BLOCK OF members");
					header( "location: ../index1.php" );
				}
			}
		}
			
  }
?>